package me.xhy.java.springboot3.webflux.s05filter;

import io.netty.util.internal.ResourcesUtil;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.http.server.reactive.ServerHttpResponse;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import org.springframework.web.server.WebFilter;
import org.springframework.web.server.WebFilterChain;
import reactor.core.publisher.Mono;

@Component
public class S052Filter implements WebFilter {

  @Override
  public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) {
    ServerHttpRequest request = exchange.getRequest();
    ServerHttpResponse response = exchange.getResponse();



    System.out.println("目标方法执行前");
    /*
    Mono<Void> filter = chain.filter(exchange);
    System.out.println(" !!! 不是目标方法执行后，因为异步，代码不是顺序执行");
    */
    Mono<Void> voidMono = chain.filter(exchange)
        .doOnError(throwable -> {
          System.out.println("目标方法异常后");
        })
        .doFinally(signalType -> {
          System.out.println("执行目标方法之后");
        });

    return voidMono;
  }
}
